require "import"
import "android.widget.*"
import "com.androlua.*"
import "android.app.AlertDialog"
import "java.io.*"
layout={LinearLayout,
layout_width=-1,
layout_height="10%h",
orientation=1,
background="#ff1e8ae8";
{
LinearLayout,
orientation=0,
layout_width=-1,
{
EditText,
id="edit",
InputType="number",
textSize="50sp",
layout_width="99.9%w",
layout_height="60%h",
background="#FF000000",﻿
},
},
{
LinearLayout,
orientation=0,
layout_width=-1,
{
Button,
text="1",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
},
{
Button,
text="2",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
},
{
Button,
text="3",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
}},
{
LinearLayout,
orientation=0,
layout_width=-1,
{
Button,
text="4",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
},
{
Button,
text="5",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
},
{
Button,
text="6",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
}},
{
LinearLayout,
orientation=0,
layout_width=-1,
{
Button,
text="7",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
},
{
Button,
text="8",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
},
{
Button,
text="9",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
}},
{
LinearLayout,
orientation=0,
layout_width=-1,
{
Button,
text="*",
onClick="click",
textColor="#ffffffff",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
},
{
Button,
text="0",
onClick="click",
textColor="#ffffff58",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
},
{
Button,
text="#",
onClick="click",
textSize="50sp",
layout_width="33%w",
layout_height="6%h",
}},
{
LinearLayout,
orientation=0,
layout_width=-1,
{
Button,
text=",",
contentDescription="phẩy",
onClick="ww",
onLongClickListener={onLongClick=function(v)
    return (_G["voice"])(v)
end},
textSize="40sp",
layout_width="25%w",
layout_height="10%h",
},
{
Button,
text="call",
contentDescription="gọi",
onClick="call",
onLongClickListener={onLongClick=function(v)
    return (_G["past"])(v)
end},
textColor="#ff00ff00",
textSize="40sp",
layout_width="33%w",
layout_height="10%h",
},
{
Button,
text="delete",
contentDescription="xoá",
onClick="xx",
onLongClickListener={onLongClick=function(v)
    return (_G["setText"])(v)
end},
textColor="#ffff7600",
textSize="40sp",
layout_width="33%w",
layout_height="10%h",
}}}

dlg=LuaDialog()
.setView(loadlayout(layout))
.setTitle("trình quay số ")
dlg.setButton("quay lại", nil)
.show()

function click(v)
edit.text=edit.text..v.getText()
service.speak(edit.getText().toString())
end

function xx()
edit.text=utf8.sub(edit.text,1,-2)
service.speak(edit.getText().toString())
if edit.text==""
service.speak("không có số để xóa")
end
end
function ww(v)
if edit.text==""
service.speak("bạn phải nhập ít nhất một số trước khi điền vào dấu phẩy")
else 
edit.text=edit.text..v.getText()
service.speak(edit.getText().toString())
end
end

function setText()
service.execute("清空")
return true
end

function past()
service.execute("粘贴")
return true
end


function voice()
service.execute("语音输入")
return true
end
function call()
if edit.text==""
service.speak("bạn chưa nhập số để gọi")
else 
gt= edit.getText().toString()
  require 'import'
  import "android.content.*"
  import "android.net.*"
  i= Intent(Intent.ACTION_CALL, Uri.parse("tel:" .. Uri.encode(gt)))
  this.startActivity(i)
dlg.hide()
end
end